package com.ptswitch.material.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true)
public class BomMaterial implements Serializable,Comparable<BomMaterial> {

	private static final long serialVersionUID = 6705569910023553421L;
	@Id
	@GeneratedValue(generator = "hibernateuuid")
	@GenericGenerator(name = "hibernateuuid", strategy = "uuid")
	@Column(length = 32)
	private String id;

	@ManyToOne(fetch = FetchType.EAGER)
	@NotFound(action = NotFoundAction.IGNORE)
	@JoinColumn(name ="code",referencedColumnName="code",insertable=false,updatable=false )
	private Material material;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@NotFound(action = NotFoundAction.IGNORE)
	private Bom bom;

	@Column(columnDefinition="varchar(32) default ''")
	private String code;
	
	@Column(columnDefinition="varchar(2048) default ''")
	private String designator;//元件编号
	
	@Column(columnDefinition="varchar(2048) default ''")
	private String comment;//规格描述
	
	@Column(columnDefinition="varchar(2048) default ''")
	private String footprint;//PCB封装
	
	@Column(columnDefinition="varchar(2048) default ''")
	private String value;
	@Column(columnDefinition="varchar(2048) default ''")
	private String voltage;//电压
	@Column(columnDefinition="varchar(2048) default ''")
	private String quantity;//数量
	@Column(columnDefinition="varchar(2048) default ''")
	private String stuffOpt;//材料选择

	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Material getMaterial() {
		return material;
	}

	public void setMaterial(Material material) {
		this.material = material;
	}

	public Bom getBom() {
		return bom;
	}

	public void setBom(Bom bom) {
		this.bom = bom;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getDesignator() {
		return designator;
	}

	public void setDesignator(String designator) {
		this.designator = designator;
	}

	public String getFootprint() {
		return footprint;
	}

	public void setFootprint(String footprint) {
		this.footprint = footprint;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getVoltage() {
		return voltage;
	}

	public void setVoltage(String voltage) {
		this.voltage = voltage;
	}

	public String getQuantity() {
		return quantity;
	}

	public void setQuantity(String quantity) {
		this.quantity = quantity;
	}

	public String getStuffOpt() {
		return stuffOpt;
	}

	public void setStuffOpt(String stuffOpt) {
		this.stuffOpt = stuffOpt;
	}
	
	public String toString() {
		return this.code + "::(" + this.material + ")::(" + this.bom+")";
	}
	
	public String print() {
		StringBuilder sb = new StringBuilder();
		sb
		.append("(materiel:").append(material)
		.append("),(bom:").append(bom)
		.append("),code:").append(code)
		.append(
				",designator:").append(designator).append(",footprint:").append(
				footprint).append(",value:").append(value).append(",voltage:")
				.append(voltage).append(",quantity:").append(quantity)
				.append(",stuffOpt:").append(stuffOpt);
		return sb.toString();
	}

	public boolean equals(Object o) {
		if (o != null && o instanceof BomMaterial) {
			return this.material.getCode().equals(
					((BomMaterial) o).getMaterial().getCode());
		}
		return false;
	}

	public int compareTo(BomMaterial o) {
		return this.code.compareTo(o.getCode());
	}

}
